﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DAL
/// </summary>
public class DAL
{
    SqlConnection SqlCn;
	public DAL()
	{
		//
		// TODO: Add constructor logic here
		//
        SqlConnectionStringBuilder cnBuild = new SqlConnectionStringBuilder();
        cnBuild.DataSource = "(local)\\NBE_posserver";
        cnBuild.InitialCatalog = "AhliBank_inventory";
        cnBuild.UserID = "sa";
        cnBuild.Password = "P@$$w0rD";
        SqlCn = new SqlConnection(cnBuild.ConnectionString);

        try
        {
            SqlCn.Open();
        }

        catch
        {}
	}

    public DataSet GetAllMerchants()
    {
        string cmd1 = "select * from MachineLog";
        string cmd2 = "select * from LogStatus";
        
        DataSet ds = new DataSet();
        SqlDataAdapter dA = new SqlDataAdapter(cmd1, SqlCn);
        dA.Fill(ds,"Log");
        dA.SelectCommand = new SqlCommand(cmd2,SqlCn);
        dA.Fill(ds, "Status");
        return ds; 
    }

    public SqlDataReader BoundMerchants()
    {
        string cmd1 = "select POS_Mach_SN as SN, pos_Mach_location from POS_Machine";
        SqlCommand sqlCmd = new SqlCommand(cmd1,SqlCn);
        SqlDataReader reader = sqlCmd.ExecuteReader();
        return reader;
    }
}